<!DOCTYPE html>
<html>
{include file="public/head" /}
<body>


<div class="layui-fluid" id="app">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card" >
                <!--<div class="layui-card-header"  style="padding-left: 20px;font-size: 20px">订单管理</div>-->
                <div class="layui-card-body">
                    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                        <ul class="layui-tab-title">
                            <li class="layui-this"  onclick="go('index')">全部</li>
                            <li  onclick="go('index1')">待处理</li>
                            <li  onclick="go('index2')">处理中</li>
                            <li  onclick="go('index3')">已完成</li>
                            <li  onclick="go('index4')">已取消</li>
                        </ul>


                        <div class="layui-tab-content" style="padding-left: 0px;padding-right: 0px">
                          <!--全部-开始-->
                            <div class="layui-tab-item layui-show">

                                <div>
                                    <div class="layui-btn-group">
                                        <button class="layui-btn " onclick="del();">删除</button>
                                    </div>
                                    <div class="layui-inline" style="float: right">
                                        <form class="layui-form" action="">
                                            <div class="layui-form-item" style="margin-bottom: 0px">
                                                <div class="layui-inline" style="margin-right: 0px">
                                                    <!--<label class="layui-form-label">密码</label>-->
                                                    <div class="layui-input-inline" style="width: 200px;">
                                                        <input type="text" name="keyword" autocomplete="off"
                                                               placeholder="请输入订单号查询"
                                                               class="layui-input">
                                                    </div>
                                                </div>

                                                <div class="layui-inline" style="margin-right: 0px">

                                                    <div class="layui-btn-group layui-inline" style="margin: 0px">
                                                        <!--此重置 仅仅是个跳转链接-->
                                                        <button  onclick="go('index')" class="layui-btn layui-btn-primary">重置</button>
                                                        <button class="layui-btn layui-btn-normal" lay-submit
                                                                lay-filter="formDemo"   style="background-color: #009688;">
                                                            <!--<i class="layui-icon">&#xe615;</i>-->
                                                            查找
                                                        </button>

                                                    </div>


                                                </div>


                                            </div>
                                        </form>


                                    </div>
                                </div>

                                <div class="layadmin-trailer ">


                                    <table class="layui-table" lay-skin="line">

                                        <thead>
                                        <tr>
                                            <th style="width: 5%"></th>
                                            <!--<th>#ID</th>-->
                                            <th>订单号</th>
                                            <th >客户</th>
                                            <th >创建时间</th>
                                            <th >订单状态</th>
                                            <th >商品总台</th>
                                            <th >操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="(item,index) in items" :data_id="item.id">
                                            <!--<td style="width: 20px;text-align: center">-->
                                                <!--<input type="checkbox" class="vue_index" name="id" :value="item.id"-->
                                                       <!--style="zoom: 150%">-->
                                            <!--</td>-->
                                            <!--<td>{{item.id}}</td>-->
                                            <td></td>
                                            <td>{{item.order_id}}</td>
                                            <td>{{item.name2}}</td>
                                            <td>{{item.createtime}}</td>
                                            <td>
                                                <span style="color: red"    v-if="item.status == 0">待处理</span>
                                                <span   v-if="item.status == 1">处理中</span>
                                                <span   v-if="item.status == 2">已完成</span>
                                                <span v-if="item.status == 3">已取消</span>
                                            </td>
                                            <td>{{item.updatetime}}</td>
                                            <td>

                                                <div class="layui-btn-group">

                                                    <button class="layui-btn layui-btn-sm layui-btn-primary"
                                                            :data_id="item.id" :data_index="index"  :data_status="item.status"  onclick="handle(this)">处理中
                                                    </button>
                                                    <button class="layui-btn layui-btn-sm layui-btn-primary"
                                                            :data_id="item.id" :data_index="index"  :data_status="item.status"  onclick="finish(this)">已完成
                                                    </button>
                                                    <button class="layui-btn layui-btn-sm layui-btn-primary"
                                                            :data_id="item.id" :data_index="index"  :data_status="item.status"  onclick="cannel(this)">取消
                                                    </button>
                                                    <button class="layui-btn layui-btn-sm layui-btn-primary"
                                                            :data_id="item.id" :data_index="index"  :data_status="item.status"  onclick="detail(this)">详情
                                                    </button>
                                                </div>

                                            </td>
                                        </tr>

                                        </tbody>
                                    </table>


                                </div>
                                <div id="demo7"></div>

                            </div>
                            <!--全部-结束-->


                        </div>
                    </div>


                </div>


            </div>

        </div>


    </div>
</div>


<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    //vue对象
    var app = new Vue({
        el: '#app',
        data: {
            check: [],
            curr: 1,//当前页
            limit: 10,//当前页
            items: []
        }
    });

    //初始数据
    function init(flag) {
        layer.load(2);
        $.get('/dc/order/index', {page: app.curr, limit: app.limit,flag: flag},
            function (res) {
                layer.closeAll();
                app.items = res.data;
            }
        );
    }

    function detail(that) {

        var data_id = $(that).attr('data_id');
        console.log(data_id);
        layer.open({

            type: 2,
            title: '订单详情',
            shadeClose: true,
            shade: 0.01,
            area: ['60%', '60%'],
            content: "{:url('detail')}?id=" + data_id //iframe的url

        });


    }


    //获取批量IDS
    function getCheckBox() {
        var check = [];
        $.each($('input[type=checkbox]:checked.vue_index'), function () {
            check.push($(this).val());
        });
        return check;
    }


    function del(that) {
        var ids = getCheckBox();
        if (ids.length > 0) {
            var index = layer.confirm('确认继续执行？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.post('{:url("del")}', {ids: ids}, function (res) {
                    if (res.code == 1) {
                        layer.msg(res.msg, {icon: 1})
                        $("input:checkbox").removeAttr("checked");
                        init();
                    }
                    layer.close(index);
                });
            }, function () {
                layer.close(index);
            });
        }


    }

    //处理中按钮
    function handle(that) {

        var data_id = $(that).attr('data_id');
        var data_status = $(that).attr('data_status');
        console.log(data_id);
        if(data_status == 1){
            alert("现在已是处理中状态");
        }

        else if(data_id) {
            var index = layer.confirm('确认修改为处理中？', {
                btn: ['确定', '取消'] //按钮

            }, function () {
                console.log("btn");
                $.post('{:url("handle")}', {data_id: data_id}, function (res) {
                    console.log("post");
                    if (res.code == 1) {
                        layer.msg(res.msg, {icon: 1})
                        init();
                        console.log(init);
                    }
                    layer.close(index);
                });
            }, function () {
                layer.close(index);
            });
        }


    }
    //已完成按钮
    function finish(that) {

        var data_id = $(that).attr('data_id');
        var data_status = $(that).attr('data_status');
        console.log(data_id);
        if(data_status == 2){
            alert("现在已是已完成状态");
        }

        else if (data_id) {
            console.log(data_id+"hghgh");
            var index = layer.confirm('确认修改为已完成？', {
                btn: ['确定', '取消'] //按钮

            }, function () {
                console.log("btn");
                $.post('{:url("finish")}', {data_id: data_id}, function (res) {
                    console.log("post");
                    if (res.code == 1) {
                        layer.msg(res.msg, {icon: 1})
                        init();
                        console.log(init);
                    }
                    layer.close(index);
                });
            }, function () {
                layer.close(index);
            });
        }


    }

    //已取消按钮
    function cannel(that) {

        var data_id = $(that).attr('data_id');
        var data_status = $(that).attr('data_status');
        console.log(data_id);
        if(data_status == 3){
            alert("现在已是已取消状态");
        }

        else if (data_id) {
            console.log(data_id+"hghgh");
            var index = layer.confirm('确认修改为已取消？', {
                btn: ['确定', '取消'] //按钮

            }, function () {
                console.log("btn");
                $.post('{:url("cannel")}', {data_id: data_id}, function (res) {
                    console.log("post");
                    if (res.code == 1) {
                        layer.msg(res.msg, {icon: 1})
                        init();
                        console.log(init);
                    }
                    layer.close(index);
                });
            }, function () {
                layer.close(index);
            });
        }


    }

    //按需引入layui模块
    layui.use(['laypage', 'layer','table','element','form'], function () {
        var laypage = layui.laypage
            , layer = layui.layer;
        var table = layui.table;
        var element = layui.element;

        element.on('tab(docDemoTabBrief)', function(data){
//            console.log(this); //当前Tab标题所在的原始DOM元素
            console.log(data.index); //得到当前Tab的所在下标
//            console.log(data.elem); //得到当前的Tab大容器
            if(data.index==0){
                init();
            }
        });


        //完整功能
        laypage.render({
            elem: 'demo7'
            , count: "{$count}"
            , limits: [10, 20]
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
            , jump: function (obj) {
                console.log(obj)
                app.curr = obj.curr;
                app.limit = obj.limit;
                init();
            }
        });

    });


    //Demo
    layui.use('form', function () {
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function (data) {
//            layer.msg(JSON.stringify(data.field));
            if (!data.field.keyword) {
                return false;
            }


            layer.load(2);
            $.get('/dc/order/base_so', data.field,
                function (res) {

                    layui.use(['laypage'], function () {
                        var laypage = layui.laypage;
                        //完整功能
                        laypage.render({
                            elem: 'demo7'
                            , count: res.total
                            , limits: [10, 20]
                            , layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
                            , jump: function (obj) {
                                console.log(obj)
                                app.curr = obj.curr;
                                app.limit = obj.limit;
                                layer.load(2);
                                $.get('/dc/order/base_so', {
                                        page: app.curr,
                                        limit: app.limit,
                                        keyword: data.field.keyword
                                    },
                                    function (res) {
                                        layer.closeAll();
                                        app.items = res.data;
                                    }
                                );
                            }
                        });
                    });
                }
            );
            return false;
        });
    });



    function sta(f) {

        console.log(f);
        flag = f;
        app.cur_page = 1;
        app.limit = 10;
        app.items = [];
        init(flag);
    }
</script>


</body>
</html>




